package com.redis.demo.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author zqf
 * @Date 2022/10/28 10:16
 * @Description:
 */

@RestController("/pub")
@Api(tags = "redis的发布和订阅")
public class RedisPubController {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @GetMapping("/publish")
    @ApiOperation("发布消息到渠道")
    public void publish() {

        //向通道channel_first发布消息hello world
        redisTemplate.convertAndSend("channel_first", "hello world");
    }


    @GetMapping("/leftPush")
    @ApiOperation("发布消息到消息队列")
    public void leftPush() {
        redisTemplate.opsForList().leftPushAll("queue","1","2","3");
    }

}
